// import './public-path';
import Vue from 'vue';
import App from './App.vue';
import store from './store';
import router from './router';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import '@/assets/index.css';
import fPlugins from '@/plugin/index';
import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper';

Vue.use(ElementUI);
Vue.use(fPlugins);

let instance = null;
const render = (props = {}) => {
  const { container } = props;
  instance = new Vue({
    router,
    store,
    render: (h) => h(App)
  }).$mount(container ? container.querySelector('#app') : '#app');
};

renderWithQiankun({
  bootstrap() {
    // do nothing.
  },
  mount(props) {
    render(props);
  },
  unmount() {
    instance.$destroy();
    instance.$el.innerHTML = '';
    instance = null;
  }
});

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render();
}
(function () {
  if (window.__POWERED_BY_QIANKUN__) {
    // eslint-disable-next-line no-undef
    __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
  }
})();
